package com.game.commands
{
	import com.game.views.RegRoleMediator;
	import com.module.login.LoginManager;
	import com.module.regrole.RegRoleManager;
	
	import flash.events.Event;
	
	import mx.core.Application;
	import mx.events.ModuleEvent;
	import mx.modules.IModuleInfo;
	import mx.modules.ModuleLoader;
	import mx.modules.ModuleManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class RegRoleCommand extends SimpleCommand
	{
		public static var NAME:String = "RegRoleCommand";
		
		public function RegRoleCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void
		{
			var loader:ModuleLoader = new ModuleLoader();
			loader.addEventListener(ModuleEvent.READY,onModuleReadyUseModuleManager);
			loader.loadModule("RoleReg.swf");
//			var module:IModuleInfo = ModuleManager.getModule("RoleReg.swf");
//			module.addEventListener(ModuleEvent.READY,onModuleReadyUseModuleManager);
//			module.load();
		}
		
		private function onModuleReadyUseModuleManager(event:Event):void{     
			var me:ModuleEvent = event as ModuleEvent; 
			RegRoleManager.rolereg = me.module.factory.create() as RoleReg;         
			Application.application.addChild(RegRoleManager.rolereg);
			if(!this.facade.hasMediator(RegRoleMediator.NAME)){
				this.facade.registerMediator(new RegRoleMediator(RegRoleMediator.NAME,RegRoleManager.rolereg));
			}
		}
	}
}